import time
from wordpress_project.base.base_page import Tools


class adduser_tool(Tools):
    """页面元素定位"""
    get_user = '[href="users.php"] [class="wp-menu-name"]'  # 用户css定位
    get_add_user = '[href="user-new.php"]'   # 添加用户css定位
    add_username = '[name="user_login"]'     # 添加用户名css定位
    add_email = '[id="email"]'     # 添加邮箱css定位
    add_user_btn = '[id="createusersub"]'   # 添加用户按钮css定位
    adduser_success_ele = '[id="message"]'  # 添加成功之后的断言定位
    adduser_fail_ele = '[class="error"]'  # 添加失败 之后的 断言定位
    user_empty = 'tbody tr'

    def add_user_action(self, adduser, email):
        self.by_css(self.get_user).click()
        time.sleep(0.5)
        self.by_css(self.get_add_user).click()
        time.sleep(0.5)
        self.by_css(self.add_username).send_keys(adduser)
        time.sleep(0.5)
        self.by_css(self.add_email).send_keys(email)
        time.sleep(0.5)
        self.by_css(self.add_user_btn).click()
        time.sleep(0.5)

    def get_success_msg(self):
        return self.by_css(self.adduser_success_ele).text

    def get_fail_msg(self):
        return self.by_css(self.adduser_fail_ele).text

    def get_empty(self):
        return self.by_css(self.user_empty).get_attribute('class')


